package cn.xuguowen.user.designPatten.template.jdbctemplate;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.StatementCallback;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * ClassName: JdbcTemplateDemo
 * Package: cn.xuguowen.user.designPatten.template.jdbctemplate
 * Description:
 * 模板设计模式在JdbcTemplate中的实现
 * @Author 徐国文
 * @Create 2023/4/25 9:30
 * @Version 1.0
 */
public class JdbcTemplateDemo {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private TransactionTemplate transactionTemplate;

    public void demo() {
        Object execute = jdbcTemplate.execute(new StatementCallback<Object>() {
            @Override
            public Object doInStatement(Statement statement) throws SQLException, DataAccessException {
                return null;
            }
        });

        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                return;
            }
        });

    }
}
